package com.cskaoyan.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author stone
 * @date 2022/05/04 16:15
 */
@Configuration
public class DataSourceConfiguration {

    @Value("${cskaoyan.datasource.driver-class-name}")
    String driverClass; // = "com.mysql.jdbc.Driver";
    @Value("${cskaoyan.datasource.url}")
    String jdbcUrl; // = "jdbc:mysql://localhost:3306/cskaoyan_db?useUnicode=true&characterEncoding=utf-8";
    @Value("${cskaoyan.datasource.username}")
    String username; // = "root";
    @Value("${cskaoyan.datasource.password}")
    String password; // = "123456";

    @Bean
    public DataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClass);
        dataSource.setUrl(jdbcUrl);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
